import { axiosInstance } from './request'

const uploadAPI = {
  uploadScreenshots(filesOrFormData) {
    let formData
    if (filesOrFormData instanceof FormData) {
      formData = filesOrFormData
    } else if (Array.isArray(filesOrFormData)) {
      formData = new FormData()
      filesOrFormData.forEach(file => formData.append('screenshots', file))
    } else {
      formData = new FormData()
      formData.append('screenshots', filesOrFormData)
    }
    return axiosInstance({
      url: '/upload/screenshots',
      method: 'post',
      data: formData,
      headers: { 'Content-Type': 'multipart/form-data' }
    })
  }
}
export default uploadAPI